import 'dart:ffi';
import '../../network/http_entity.dart';

class MediaCommentEntity {
  final int? commentId;
  final String? mediaId;
  final String? content;
  final int? fromUid;
  final int? likeCount;
  final String? createTime;
  final int? toUid;
  final String? avatar;
  final String? nickName;
  final String? recontent;
  MediaCommentEntity({
    required this.commentId,
    required this.mediaId,
    required this.content,
    required this.fromUid,
    required this.likeCount,
    required this.createTime,
    required this.toUid,
    required this.avatar,
    required this.nickName,
    required this.recontent
  });

  factory MediaCommentEntity.fromJson(Map<String, dynamic> json) {
    return MediaCommentEntity(
      commentId: json['commentId'],
      mediaId: json['mediaId'],
      content: json['content'],
      fromUid: json['fromUid'],
      likeCount: json['likeCount'],
      createTime: json['createTime'],
      toUid: json['toUid'],
      avatar: json['avatar'],
      nickName: json['nickName'],
      recontent: json['recontent']
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'commentId': commentId,
      'mediaId': mediaId,
      'content': content,
      'fromUid': fromUid,
      'likeCount': likeCount,
      'createTime': createTime,
      'toUid': toUid,
      'avatar': avatar,
      'nickName': nickName,
      'recontent': recontent
    };
  }
}

class MediaCommentEntityList {
  final List<MediaCommentEntity> mediaCommentEntityList;
  final int? pageCurrent;
  final int? pageSize;
  final int? total;
  final bool? hasNext;
  final int? pages;

  MediaCommentEntityList({
    required this.mediaCommentEntityList,
    this.pageCurrent,
    this.pageSize,
    this.total,
    this.hasNext,
    this.pages,
  });

  factory MediaCommentEntityList.fromJson(List<dynamic> json, dynamic result) {
    HttpEntity httpEntity = result;
    List<MediaCommentEntity> imageTexts = json.map<MediaCommentEntity>((item) {
      MediaCommentEntity mediaCommentEntity = MediaCommentEntity(
        commentId: item['commentId'],
        mediaId: item['mediaId'],
        content: item['content'],
        fromUid: item['fromUid'],
        likeCount: item['likeCount'],
        createTime: item['createTime'],
        toUid: item['toUid'] == null ? 0 : item['toUid'],
        avatar: item['avatar'],
        nickName: item['nickName'],
        recontent: item['recontent']
        // 其他属性...
      );
      return mediaCommentEntity;
    }).toList();

    return MediaCommentEntityList(
      mediaCommentEntityList: imageTexts,
      pageCurrent: httpEntity.oriData['pageCurrent'],
      pageSize: httpEntity.oriData['pageSize'],
      total: httpEntity.oriData['total'],
      hasNext: httpEntity.oriData['hasNext'],
      pages: httpEntity.oriData['pages'],
      // 其他属性...
    );
  }

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    if (mediaCommentEntityList != null) {
      map['mediaCommentEntityList'] = mediaCommentEntityList?.map((v) => v.toJson()).toList();
    }
    map['pageCurrent'] = pageCurrent;
    map['pageSize'] = pageSize;
    map['total'] = total;
    map['hasNext'] = hasNext;
    map['pages'] = pages;
    return map;
  }
}
